package com.ruoyi.web.controller.warehouse;

import java.util.Date;
import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.utils.SecurityUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.warehouse.domain.WareHouseFish;
import com.ruoyi.warehouse.service.IWareHouseFishService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 仓库中心=》观赏鱼Controller
 * 
 * @author 杨彬鑫
 * @date 2020-12-30
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/warehouse/fish" )
public class FishController extends BaseController {

    private final IWareHouseFishService iWareHouseFishService;

    /**
     * 查询仓库中心=》观赏鱼列表
     */
    @PreAuthorize("@ss.hasPermi('warehouse:fish:list')")
    @GetMapping("/list")
    public TableDataInfo list(WareHouseFish wareHouseFish) {
        startPage();
        List<WareHouseFish> list = iWareHouseFishService.queryList(wareHouseFish);
        return getDataTable(list);
    }

    /**
     * 导出仓库中心=》观赏鱼列表
     */
    @PreAuthorize("@ss.hasPermi('warehouse:fish:export')" )
    @Log(title = "仓库中心=》观赏鱼" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(WareHouseFish wareHouseFish) {
        List<WareHouseFish> list = iWareHouseFishService.queryList(wareHouseFish);
        ExcelUtil<WareHouseFish> util = new ExcelUtil<WareHouseFish>(WareHouseFish.class);
        return util.exportExcel(list, "fish" );
    }

    /**
     * 获取仓库中心=》观赏鱼详细信息
     */
    @PreAuthorize("@ss.hasPermi('warehouse:fish:query')" )
    @GetMapping(value = "/{fishcode}" )
    public AjaxResult getInfo(@PathVariable("fishcode" ) String fishcode) {
        return AjaxResult.success(iWareHouseFishService.getById(fishcode));
    }

    /**
     * 新增仓库中心=》观赏鱼
     */
    @PreAuthorize("@ss.hasPermi('warehouse:fish:add')" )
    @Log(title = "仓库中心=》观赏鱼" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WareHouseFish wareHouseFish) {
        wareHouseFish.setCreateBy(SecurityUtils.getUsername());
        wareHouseFish.setCreateTime(new Date());
        return toAjax(iWareHouseFishService.save(wareHouseFish) ? 1 : 0);
    }

    /**
     * 修改仓库中心=》观赏鱼
     */
    @PreAuthorize("@ss.hasPermi('warehouse:fish:edit')" )
    @Log(title = "仓库中心=》观赏鱼" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WareHouseFish wareHouseFish) {
        wareHouseFish.setUpdateBy(SecurityUtils.getUsername());
        wareHouseFish.setUpdateTime(new Date());
        return toAjax(iWareHouseFishService.updateById(wareHouseFish) ? 1 : 0);
    }

    /**
     * 删除仓库中心=》观赏鱼
     */
    @PreAuthorize("@ss.hasPermi('warehouse:fish:remove')" )
    @Log(title = "仓库中心=》观赏鱼" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{fishcodes}" )
    public AjaxResult remove(@PathVariable String[] fishcodes) {
        return toAjax(iWareHouseFishService.removeByIds(Arrays.asList(fishcodes)) ? 1 : 0);
    }
}
